package luj.tool.jnproxyan.proxy.network.https.client;

import io.netty.buffer.ByteBuf;
import io.netty.channel.embedded.EmbeddedChannel;

import java.io.IOException;
import java.io.OutputStream;

final class StreamReceiveFrom extends OutputStream {

  @Override
  public void write(int b) throws IOException {
    ByteBuf in = _channel.alloc().buffer(1).writeByte(b);
//    System.out.println("s->p: [1]");
    _channel.writeInbound(in);
  }

  @Override
  public void write(byte[] b, int off, int len) throws IOException {
    ByteBuf in = _channel.alloc().buffer(len).writeBytes(b, off, len);
//    System.out.println("s->p: " + len);
    _channel.writeInbound(in);
  }

  @Override
  public void flush() throws IOException {
//    System.out.println("s->p: flush");
    _channel.flushInbound();
  }

  @Override
  public void close() throws IOException {
//    System.out.println("s->p: close");
    _channel.close();
  }

  EmbeddedChannel _channel;
}
